/**
 * Created by xxx on 2017/3/27.
 */var height = $(document.body).height()+"px";
//用react封装
var currentpage = 1,totlepage = 1,i,tempCurrentPage = 1;//分页的当前页和总的页数
//表单数据：学校页面的对应注解：学校名称 考勤区域  隶   属地区 设备自定义套餐（扩展）学校id
var simData = [],importSimData = [],importSimRepeatData = [];
var importSim = {isImportSim:false};//是否导入
var allSimCount = 0; //每个批次下面的设备总量
//表单的最高高度、当前第几页、总页数、总行数、设备投放切换、箱号
var otherData = {maxHeight:'0px',currentpage:0,totlepage:0,totlerows:0,pageLeft:0,pageRight:0,view:'',boxOrdevice:'device',batchNumber:'',upBatchNumber:''};
var Page = React.createClass({
    setPage: function (e) {
        setPage($(e.target).html());
        this.props.onPageClick(1);
    },
    showPage: function () {
        showPage();
    },
    render: function () {
        {
            var items = [],
                svar = this;
            if(totlepage == 0 ){
                items.push({num:1,checked:true})
            }else if(totlepage < 6){
                for(i = 1;i <= totlepage ;i++) {
                    if (i == currentpage) {
                        items.push({num:i,checked:true})
                    } else {
                        items.push({num:i,checked:false})
                    }
                }
            }else if(currentpage >= (totlepage-2)) {//点在左边
                items.push({num:1,checked:false});
                items.push({num:'···',checked:false});
                for(i = totlepage-2;i <= totlepage ;i++){
                    if(i == currentpage){
                        items.push({num:i,checked:true})
                    }else{
                        items.push({num:i,checked:false})
                    }
                }
            }else if(currentpage <= 3){
                for(i = 1;i <= 3 ;i++) {
                    if (i == currentpage) {
                        items.push({num:i,checked:true})
                    } else {
                        items.push({num:i,checked:false})
                    }
                }
                items.push({num:'···',checked:false});
                items.push({num:totlepage,checked:false})
            }else {//点在两边
                items.push({num:1,checked:false});
                items.push({num:'···',checked:false});
                items.push({num:currentpage-1,checked:false});
                items.push({num:currentpage,checked:true});
                items.push({num:currentpage+1,checked:false});
                items.push({num:'···',checked:false});
                items.push({num:totlepage,checked:false})
            }
        }
        return (
            <div className="tableInfo-page">
                <div className="page-number">每页<span className="page-number-list" onClick={this.showPage}>{pagecount}</span>条</div>
                <div className="page-list" style={{top:pageListTop+"px"}}>
                    <ul>
                        {
                            pageList.map(function (item) {
                                return (<li onClick={svar.setPage}>{item}</li>)
                            })
                        }
                    </ul>
                </div>
                <div className="page-limit">
                    <ol className="page-limit-ol">
                        <ol className="page-limit-ol">
                            <li className="page-limit-img" name="-1" onClick={otherData.pageLeft == 0?'':svar.props.onPageClick.bind(svar,-1)} ><span className={otherData.pageLeft == 0?'page-limit-left-no':'page-limit-left-yes'}/></li>
                            {
                                items.map(function (item) {
                                    return (<li onClick={isNaN(item.num)?'':svar.props.onPageClick.bind(svar,item.num)}  className={item.checked == true?'page-limit-num page-limit-checked':'page-limit-num'} name={item.num}>{item.num}</li>)
                                })
                            }
                            <li className="page-limit-img" name="-2" onClick={otherData.pageRight == 0?'':svar.props.onPageClick.bind(svar,-2)} ><span className={otherData.pageRight == 0?'page-limit-right-no':'page-limit-right-yes'}/></li>
                        </ol>
                    </ol>
                </div>
            </div>
        );
    },
});
/**
 * sim表单
 * @type {*}
 */
var SIMTable = React.createClass({
    clickChecked: function () {
        var childsCheckBox = $(".SIMDelivery-body").children();
        var b = 0,a = 0;
        for(var i = 0;i<childsCheckBox.length;i++){
            var child = $($(childsCheckBox[i]).children()[0]).children();
            if($(child[0]).length == 0){
                a ++;
            }
            if($(child[0]).is(':checked')){
                b ++;
            }
        };
        if(b == childsCheckBox.length-a){
            $(".simCheckBox").prop('checked',true);
        }else{
            $('.simCheckBox').attr('checked',false);
        }
    },
    render: function () {
        {
            var status = "未知",statusColor = '-2';//‘已回收’修改成‘未知’
            if(this.props.status == "0"){
                status = "未开机匹配";
                statusColor = '0';
            }else  if(this.props.status == "1"){
                status = "已使用";
                statusColor = '1';
            }else  if(this.props.status == "-1"){
                status = "已注销";
                statusColor = '-1';
            }
        }
        return (
            <tr>
                <td style={{width: '3%'}}>{this.props.status!='-1'?<input onClick={this.clickChecked} className="simChildCheckBox" data-value={this.props.id} type="checkbox"/>:""}</td>
                <td style={{width: '4%'}}>{parseInt(this.props.listNumber)+1}</td>
                <td style={{width: '8%'}}>{this.props.operations}</td>
                <td style={{width: '8%'}}>{this.props.phone}</td>
                <td style={{width: '9%'}}>{this.props.iccid}</td>
                <td style={{width: '8%'}}><span style={{color:this.props.peoplename==null || this.props.peoplename==''?(statusColor=="0"?'#FF5959':'#000000'):'#000000'}}>{this.props.peoplename==null || this.props.peoplename==''?(statusColor=="0"?'未激活':''):this.props.peoplename}</span></td>
                <td style={{width: '9%'}}>{this.props.peopleidcard}</td>
                <td style={{width: '8%'}}>{this.props.mdtid}</td>
                <td style={{width: '8%'}}>{this.props.bindtime}</td>
                <td style={{width: '8%'}}><span style={{color:statusColor=="0"?"#FF5959":(statusColor=="-2"?"#01b4ee":"#000000")}}>{status}</span></td>
            </tr>
        );
    }
});
/**
 * 导入sim卡
 * @type {*}
 */
var ImportSIMTable = React.createClass({
    render: function () {
        return (
            <tr>
                <td style={{width: '10%'}}>{parseInt(this.props.listNumber)+1}</td>
                <td style={{width: '20%'}}>{this.props.operations}</td>
                <td style={{width: '20%'}}>{this.props.phone}</td>
                <td style={{width: '25%'}}>{this.props.iccid}</td>
                <td style={{width: '25%'}}>{this.props.createtimestr}</td>
            </tr>
        );
    }
});
/**
 * 新增sim卡弹出层
 * @type {*}
 */
var AddSIM = React.createClass({
    //关闭弹出层
    onClickHidePop: function () {
        $(".initializeMenu", window.parent.document).hide();//父页面的遮罩
        $(".addSIM").hide();
        $(".errorMsg").hide();
        $("#sim_iccid").val("")
        $("#sim_phone").val("")
    },
    //保存新增设备
    addSim: function () {
        var svar = this,sim_phone = $("#sim_phone").val(),sim_iccid = $("#sim_iccid").val();
        if(sim_phone==""){
            suixun.alert("手机号码不能为空!");
            $(".phone-error").show();
            return;
        }else if(sim_phone.length != 11){
            suixun.alert("手机号码格式错误!");
            $(".phone-error").show();
            return;
        }else if(!/^[1-9]\d*$/.test(sim_phone)){
            suixun.alert("手机号码格式错误!",function (data) {
                if(data){
                    $("#sim_phone").val("");
                }
            });
            $(".phone-error").show();
            return;
        }
        if(sim_iccid==""){
            suixun.alert("ICCID不能为空!");
            $(".ICCID-error").show();
            return;
        }else if(sim_iccid.length != 20){
            suixun.alert("ICCID格式错误!",function (data) {
                if(data){
                    $("#sim_iccid").val("");
                }
            });
            $(".ICCID-error").show();
            return;
        }else if(!/^[^\u4e00-\u9fa5]{0,}$/.test(sim_iccid)){
            suixun.alert("ICCID格式错误!");
            $(".ICCID-error").show();
            return;
        }
        var param="param={";
        param = getJsonDataNotEmpty(param,"iccid",'"'+sim_iccid+'"');
        param = getJsonDataNotEmpty(param,"phone",'"'+sim_phone+'"');
        param = getJsonDataNotEmpty(param,"operations",$("#sim_operations").val());
        param += "}";
        suixun.showLoding();//显示加载中
        suixun.ajax(serverUrl+'/simInfoManage/addSimInfo.json',param,"get",function(data){
            suixun.hideLoding(200);//隐藏加载中
            if(data!=null && data.code == 200){
                suixun.alert("新增成功",function (data) {
                    if(data){
                        svar.onClickHidePop();
                        svar.props.onPageClick(currentpage);
                    }
                });
            } else {
                suixun.alert((data!=null && data.msg!=null)?data.msg:"新增失败");
            }
        });
    },
    //查询箱号
    onClickPhoneQuery: function (e) {
        suixun.alert("查询箱号")
    },
    //验证
    onBlurInput: function (e) {
        var classname = e.target.getAttribute("data-error");
        if($(e.target).val() == ''){
            $("."+classname+"").show();
        }else{
            $("."+classname+"").hide();
        }
    },
    render: function () {
        return (
            <form name="simForm">
                <div  className="pop popPhone addSIM popModel">
                    <div className="model"></div>
                    <div className="pop-info popModel-info addSIM-info">
                        <div className="pop-title popModel-title">
                            <span className="pop-title-content popModel-title-content addSIM-popModel-title-content">
                                <span className="pop-title-content-solid-left popModel-title-content-solid-left" />
                                    新增SIM卡
                                <span className="pop-title-content-solid-right popModel-title-content-solid-right"  />
                            </span>
                            <span className="pop-title-img popModel-title-img" onClick={this.onClickHidePop}><img src="../img/icon/close.png" alt="关闭"/></span>
                            <input type="hidden" name="sim_simids" id="sim_simids" />
                        </div>
                        <div className="popModel-body">
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">运营商</span>
                                <span className="popModel-body-input-content" >
                                    <select className="export-factory" id="sim_operations">
                                       <option value="天音移动" selected="selected" >天音移动</option>
                                       <option value="中国移动" >中国移动</option>
                                        <option value="中国电信" >中国电信</option>
                                        <option value="中国联通" >中国联通</option>
                                    </select>
                                </span>
                            </div>
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">手机号码</span>
                                <span className="popModel-body-input-content">
                                    <input className="input-content " maxLength="11" data-error="phone-error" onBlur={this.onBlurInput} id="sim_phone" type="text" placeholder="请输入手机号"  />
                                </span>
                                <div className="errorMsg phone-error" ></div>
                            </div>
                            <div className="popModel-body-input">
                                <span className="popModel-body-input-title">ICCID</span>
                                <span className="popModel-body-input-content">
                                    <input className="input-content " maxLength="20" data-error="ICCID-error" onBlur={this.onBlurInput} id="sim_iccid" type="text" placeholder="请输入SIM卡ICCID"  />
                                </span>
                                <div className="errorMsg ICCID-error" ></div>
                            </div>
                        </div>
                        <div className="popModel-button" style={{marginTop:"-25px"}}>
                            <span className="popModel-button-ok" onClick={this.addSim}>确定</span>
                        </div>
                    </div>
                </div>
            </form>
        );
    }
});
/**
 * 批量导入
 * @type {*}
 */
var ExcelInput = React.createClass({
    //关闭弹出层
    onClickHidePop: function () {
        $("#inputExcelName").val("");
        $("#file").val("");
        $(".excelInput").hide();
    },
    //选择Excel文件
    onChangFile: function () {
        var fileUrl = $("#file").val().split('\\');//注split可以用字符或字符串分割
        var fileName = fileUrl[fileUrl.length-1];//这就是要取得的图片名称
        var fileLat = fileName.substring( fileName.lastIndexOf('.')+1 );//后缀名称
        if(fileLat == "xls" || fileLat == "xlsx" ){
            $(".file_name").val(fileName);
        }else{
            suixun.alert("请选择Excel文件上传!",function (data) {
                if(data){
                    $(".file_name").val("");
                }
            });
        }
    },
    render: function () {
        return (
            <div  className="pop popPhone excelInput popModel">
                <div className="model"></div>
                <div className="pop-info popModel-info excelInput-info">
                    <div className="pop-title popModel-title ">
                        <span className="pop-title-content popModel-title-content">
                            <span className="pop-title-content-solid-left popModel-title-content-solid-left" style={{width:"180px "}} />
                                批量导入
                            <span className="pop-title-content-solid-right popModel-title-content-solid-right"  style={{width:"180px "}} />
                        </span>
                        <span className="pop-title-img popModel-title-img" onClick={this.onClickHidePop}><img src="../img/icon/close.png" alt="关闭"/></span>
                    </div>

                    <div className="pop-body popModel-body">
                        <div className="popModel-body-input">
                            <span className="popModel-body-input-title" style={{width: "108px",lineHeight:"41px",backgroundPosition:"106px 0px"}}>选择Excel文件</span>
                            <form name="excelInputForm" id="excelInputFrom"  enctype="multipart/form-data" method="post">
                                <input className="file_name input-content export-imei" id="inputExcelName" type="text" name="filename" readOnly="readOnly"/>
                                <a href="javascript:;" className="file">选择文件
                                    <input type="file" onChange={this.onChangFile}  name="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel,application/vnd.ms-excel,application/vnd.ms-excel,application/vnd.ms-excel,application/vnd.ms-excel " id="file" />
                                </a>
                            </form>
                        </div>


                    </div>
                    <div className="popModel-button" style={{marginTop:"20px"}}>
                        <span className="popModel-button-ok" onClick={this.props.excelInput}>导入</span>
                    </div>
                </div>
            </div>
        );
    }
});
/**
 * 新增批号弹出层
 * @type {*}
 */
var Addbatchnumber = React.createClass({
    onClickHidePop: function () {
        $(".addBatchNumber").hide();
    },
    render: function () {
        return (
            <div  className="pop popPhone addBatchNumber">
                <div className="model"></div>
                <div className="pop-info popPhone-info">
                    <div className="pop-title popPhone-title">
                        <span className="pop-title-content popPhone-title-content">
                            <span className="pop-title-content-solid-left popPhone-title-content-solid-left"/>
                            编辑批号
                            <span className="pop-title-content-solid-right popPhone-title-content-solid-right"/>
                        </span>
                        <span className="pop-title-img popPhone-title-img" onClick={this.onClickHidePop}><img src="../img/icon/close.png" alt="关闭"/></span>
                        <input type="hidden" name="batch_id" id="batch_id"/>
                    </div>
                    <div className="pop-body">
                        <div className="pop-body-input">
                            <span className="pop-body-input-title">批号名</span>
                            <span className="pop-body-input-content">
                                <input className="input-content " type="text" placeholder="请输入批号" name="batch_batchcode" id="batch_batchcode"/>
                            </span>
                            <span className="verify imei-error" />
                        </div>
                    </div>
                    <div className="pop-button" style={{marginTop:'50px'}}>
                        <span className="pop-button-ok" onClick={this.props.onClockSaveAddbatchnumber}>保存</span>
                    </div>
                </div>
            </div>
        );
    }
});
/**
 * 查看导入数据重复弹出层弹出层
 * @type {*}
 */
var ImportSimRepeat = React.createClass({
    onClickHidePop: function () {
        $(".popPhone").hide();
    },
    render: function () {
        {
            var importSimRepeatDatas = importSimRepeatData.map(function (data,index) {
                return (
                    <tr style={{height: "36px"}}>
                        <td style={{width: '20%'}}>{parseInt(index)+1}</td>
                        <td style={{width: '30%'}}>{data.phone}</td>
                        <td style={{width: '50%'}}>{data.iccid}</td>
                    </tr>
                )
            }.bind(this));
        }
        return (
            <div className="pop popPhone popModel popImportRepeat ">
                <div className="model"></div>
                <div className="pop-info popModel-info popPhone-info">
                    <div className="pop-title popPhone-title">
                        <span className="pop-title-content popPhone-title-content">
                            <span className="pop-title-content-solid-left popPhone-title-content-solid-left"/>
                                SIM卡导入重复数据
                            <span className="pop-title-content-solid-right popPhone-title-content-solid-right"/>
                        </span>
                        <span className="pop-title-img popPhone-title-img" onClick={this.onClickHidePop}><img src="../img/icon/close.png" alt="关闭"/></span>
                        <input type="hidden" name="batch_id" id="batch_id"/>
                    </div>
                    <div className="pop-body ">
                        <div className="tableInfo importRepeatTableInfo">
                            <div className="studentsInfo-data tableInfo-data">
                                <div className="studentsInfo-data-table tableInfo-data-table" >
                                    <table className="head-body ">
                                        <thead>
                                            <th style={{width: '20%',height: "40px"}}>序号</th>
                                            <th style={{width: '30%',height: "40px"}}>手机号</th>
                                            <th style={{width: '50%',height: "40px"}}>ICCID</th>
                                        </thead>
                                        <tbody>
                                            {importSimRepeatData==""?'':importSimRepeatDatas}
                                        </tbody>
                                    </table>
                                    {importSimRepeatData==""?<div className="tableNoData">{tableNoDataCount}</div>:''}
                                </div>
                            </div>
                        </div>
                    </div>
                    <div className="messagePrompt" >注：以上为此次导入重复数据，其他数据已导入成功!</div>
                </div>
            </div>
        );
    }
});
/**
 * SIM卡投放组件
 * @type {*}
 */
var SIMDelivery = React.createClass({
    onPageClick: function (num) {
        //分页-调用ajac然后把数据查询出来:获取name的值
        //计算currentpage
        suixun.showLoding();//显示加载中
        var onPageLeft = 0,onPageRight = 1,svar = this;
        if(num > 0){
            currentpage = num;
        }else if(num == -1 && currentpage > 1){
            currentpage --;
        }else if(num == -2  && currentpage < totlepage){
            currentpage ++;
        }
        //修改左右的按钮
        if((currentpage == totlepage && totlepage == 1)|| totlepage == 0){
            onPageLeft = 0;
            onPageRight = 0;
        }else if(currentpage == totlepage && totlepage > 1){
            onPageLeft = 1;
            onPageRight = 0;
        }else if(1 < currentpage && currentpage < totlepage){
            onPageLeft = 1;
            onPageRight = 1;
        }
        //判断是不是导入页面
        if(importSim.isImportSim == true){
            importSimData = [];
            var param="param={";
            param = getJsonDataNotEmpty(param,"pagenumber",""+currentpage+"");
            param = getJsonDataNotEmpty(param,"pagecount",""+pagecount+"");
            param += "}";
            suixun.ajax(serverUrl+'/simInfoManage/querySimTmpList.json',param,"get",function(data){
                suixun.hideLoding();//隐藏加载中
                if(data.code == 200){
                    if(data.info.queryresult != null){
                        for(var i=0;i<data.info.queryresult.length;i++){
                            var obj=data.info.queryresult[i];
                            importSimData[i] = {id:i,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,createtimestr:obj.createtimestr};
                        }
                    }
                    if(data.info.totlepage > 1 && data.info.totlepage > currentpage){
                        onPageRight = 1
                    }else{
                        onPageRight = 0;
                    }
                    otherData.totlepage = data.info.totlepage;
                    otherData.totlerows = data.info.totlerows;
                    otherData.pageLeft = onPageLeft;
                    otherData.pageRight = onPageRight;
                    otherData.currentpage = currentpage;
                    totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                    svar.setState({importSimData:importSimData,otherData:otherData});
                }
            });
        }else{
            var param="param={pagenumber:"+currentpage+",pagecount:"+pagecount;
            var status = $("#sim-status").val();
            if(status == "99"){
                status = "";
            }
            param = getJsonDataNotEmpty(param,"phone",$("#sim-phone").val());
            param = getJsonDataNotEmpty(param,"status",status+"");
            param += "}";
            simData = [];
            //执行ajax获取数据然后组装
            suixun.ajax(serverUrl+'/simInfoManage/querySimInfoList.json',param,"get",function(data){
                suixun.hideLoding();//隐藏加载中
                if(data.code == 200){
                    if(data.info.queryresult != null){
                        for(var i=0;i<data.info.queryresult.length;i++){
                            var obj=data.info.queryresult[i];
                            simData[i] = {id:obj.id,bindtime:obj.bindtime,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,status:obj.status,peoplename:obj.peoplename,peopleidcard:obj.peopleidcard,mdtid:obj.mdtid};
                        }
                        otherData = {maxHeight:height,currentpage:currentpage,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:onPageLeft,pageRight:onPageRight,view:'SIMDelivery',batchNumber:'',upBatchNumber:''};
                        svar.setState({simData:simData,otherData:otherData});
                        $(".simChildCheckBox").attr("checked",false);
                        $(".simCheckBox").attr("checked",false);
                    }else{
                        suixun.alert("没有查询到数据!",function (data) {
                            if(data){
                                otherData = {maxHeight:height,currentpage:1,totlepage:1,totlerows:1,pageLeft:0,pageRight:0,view:'SIMDelivery'};
                                currentpage = 1;totlepage = 1;//初始化的时候赋值：分页的当前页和总的页数
                                svar.setState({simData:[],otherData:otherData,allSimCount:1});
                            }
                        });
                    }


                }
            });
        }
    },
    //点击下拉列表
    onClickSimStatus: function (e) {
        suixun.showLoding();//显示加载中
        var elm=e.target;
        $("#sim-status").val($(elm).attr("data-status"));
        $(".election-value").html(elm.innerHTML);//赋值
        simData = [];
        var param="param={";
        param = getJsonDataNotEmpty(param,"phone",$("#sim-phone").val());
        if(elm.innerHTML != "全部"){
            param = getJsonDataNotEmpty(param,"status",$("#sim-status").val());
        }
        param = getJsonDataNotEmpty(param,"pagecount",pagecount+"");
        param += "}";
        var svar = this;
        suixun.ajax(serverUrl+'/simInfoManage/querySimInfoList.json',param,"get",function(data){
            suixun.hideLoding();//隐藏加载中
            if(data.code == 200){
                if(data.info.queryresult != null){
                    for(var i=0;i<data.info.queryresult.length;i++){
                        var obj=data.info.queryresult[i];
                        simData[i] = {id:obj.id,bindtime:obj.bindtime,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,status:obj.status,peoplename:obj.peoplename,peopleidcard:obj.peopleidcard,mdtid:obj.mdtid};
                    }
                    var pageRight = 0;
                    if(data.info.totlepage > 1){
                        pageRight = 1
                    }
                    otherData = {maxHeight:height,currentpage:1,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:0,pageRight:pageRight,view:'SIMDelivery'};
                    currentpage = 1;totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                    allSimCount=data.info.totlerows;
                    svar.setState({simData:simData,otherData:otherData,allSimCount:allSimCount});
                    $(".simChildCheckBox").attr("checked",false);
                    $(".simCheckBox").attr("checked",false);
                }else{
                    suixun.alert("没有查询到数据!",function (data) {
                        if(data){
                            otherData = {maxHeight:height,currentpage:1,totlepage:1,totlerows:1,pageLeft:0,pageRight:0,view:'SIMDelivery'};
                            currentpage = 1;totlepage = 1;//初始化的时候赋值：分页的当前页和总的页数
                            svar.setState({simData:[],otherData:otherData,allSimCount:1});
                        }
                    });
                }
                $(".drop-down").slideUp();
            }else{
                suixun.alert(data.msg);
            }
        });
    },
    //注销SIM卡
    onClickLogoutSIM: function () {
        var idList="";
        $(".simChildCheckBox").each(function(i,box) {
            if(box!=null && box.checked)
                idList+=$(box).attr("data-value")+"|";
        });

        if(idList.length>1){
            idList=idList.substring(0,idList.length-1);
            $("#sim_simids").val(idList);
        }else{
            suixun.alert("请先选择要注销的SIM卡");
            return false;
        }
        var svar = this;
        suixun.confirm_noTit("你确定要注销选定的SIM卡吗？",function (data) {
            if (data == true) {
                suixun.showLoding();//显示加载中
                var param = "param={";
                param = getJsonDataNotEmpty(param, "ids", idList);
                param += "}";
                suixun.ajax(serverUrl + '/simInfoManage/deleteSimInfo.json',param,"get",function(data){
                    suixun.hideLoding(200);//隐藏加载中
                    if (data != null && data.code != null && data.code == 200) {
                        suixun.alert("注销成功",function (data) {
                            if(data){
                                svar.onPageClick(currentpage);
                            }
                        });
                    } else {
                        suixun.alert((data != null && data.msg != null) ? data.msg : "注销失败");
                    }
                });
            }
        });
    },
    /**
     * 新增SIM卡
     */
    onClickAddSIM: function () {
        $(".initializeMenu", window.parent.document).show();//父页面的遮罩
        $(".addSIM").show();
    },
    /**
     * 批量导入
     */
    onClickImportExcel: function () {
        $(".excelInput").show();
    },
    /**
     * 导出excel
     */
    onClickExportExcel: function () {
        suixun.confirm_noTit("是否确定导出Excel?",function (data) {
            if(data){
                var phone = $("#sim-phone").val();
                var election = $(".election-value").html();
                if(!/^[1-9]\d*$/.test(phone) && phone != ""){
                    setTimeout(function () {
                        suixun.alert("手机号格式不对！",function (data) {
                            if(data){
                                $("#sim-phone").val("")
                            }
                        });
                    },200);
                    return;
                }
                switch (election){
                    case '未使用':
                        election = '0';
                        break;
                    case '已使用':
                        election = '1';
                        break;
                    case '已注销':
                        election = '-1';
                        break;
                    default :
                        election = '';
                }
                var param="param={";
                // param = getJsonDataNotEmpty(param,"iccid",'"'+otherData.schoolname+'"');
                if(phone){
                    param = getJsonDataNotEmpty(param,"phone",'"'+phone+'"');
                }
                if(election){
                    param = getJsonDataNotEmpty(param,"status",'"'+election+'"');
                }
                // param = getJsonDataNotEmpty(param,"pagenumber",'"'+currentpage+'"');
                // param = getJsonDataNotEmpty(param,"pagecount",'"'+pagecount+'"');
                param += "}";
                window.location.href = serverUrl+'/simInfoManage/export_SimInfoList.json?'+param;
            }
        });
    },
    /**
     * 导入保存的按钮
     */
    excelInput: function () {
        var svar = this;
        var file_name = $(".file_name").val();
        if(file_name != ""){
            suixun.showLoding();//显示加载中
            var formData=new FormData($("#excelInputFrom")[0]);
            suixun.ajax(serverUrl+'/simInfoManage/importSim.json',formData,"post",function(data){
                suixun.hideLoding(200);//隐藏加载中
                if(data.code == 200 && data.info == null){//成功
                    suixun.alert('导入成功',function (data) {
                        if(data){
                            $(".excelInput").hide();
                            svar.onClickQueryLastSim();
//                                    svar.onPageClick(1);
                        }
                    })
                }else if(data.code == 200 && data.info != null){//有重复数据
                    suixun.alert('此次导入有重复数据！',function (data) {
                        if(data){
                            $(".excelInput").hide();
                            $(".popImportRepeat").show();
                        }
                    });
                    importSimRepeatData = data.info;
                    svar.setState({importSimRepeatData:importSimRepeatData});
                }else{
                    suixun.alert(data.msg)
                }
            });
        }else{
            suixun.alert("请选择上传文件!");
        }
    },
    /**
     * 输入手机号码搜索
     */
    onClickQueryPhone: function () {
        var phone = $("#sim-phone").val();
        if(!/^[1-9]\d*$/.test(phone) && phone != ""){
            suixun.alert("手机号格式不对！",function (data) {
                if(data){
                    $("#sim-phone").val("")
                }
            });
            return;
        }
        simData = [];
        var param="param={";
        param = getJsonDataNotEmpty(param,"phone",'"'+phone+'"');
        if($("#sim-status").val() != "99"){
            param = getJsonDataNotEmpty(param,"status",'"'+$("#sim-status").val()+'"');
        }
        param = getJsonDataNotEmpty(param,"pagecount",pagecount+"");
        param += "}";
        var svar = this;
        suixun.showLoding();//显示加载中
        suixun.ajax(serverUrl+'/simInfoManage/querySimInfoList.json',param,"get",function(data){
            suixun.hideLoding();//隐藏加载中
            if(data.code == 200){
                for(var i=0;i<data.info.queryresult.length;i++){
                    var obj=data.info.queryresult[i];
                    simData[i] = {id:obj.id,bindtime:obj.bindtime,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,status:obj.status,peoplename:obj.peoplename,peopleidcard:obj.peopleidcard,mdtid:obj.mdtid};
                }
                var pageRight = 0;
                if(data.info.totlepage > 1){
                    pageRight = 1
                }
                otherData = {maxHeight:height,currentpage:1,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:0,pageRight:pageRight,view:'SIMDelivery'};
                currentpage = 1;totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                allSimCount=data.info.totlerows;
                svar.setState({simData:simData,otherData:otherData,allSimCount:allSimCount});
                $(".simChildCheckBox").attr("checked",false);
                $(".simCheckBox").attr("checked",false);
            }
        });
    },
    //查询最后一次入库
    onClickQueryLastSim: function () {
        suixun.showLoding();//显示加载中
        tempCurrentPage = currentpage;
        importSimData = [];
        importSim.isImportSim = true;
        this.setState({importSim:importSim});
        var param="param={";
        param = getJsonDataNotEmpty(param,"pagenumber","1");
        param = getJsonDataNotEmpty(param,"pagecount",pagecount+'');
        param += "}";
        var svar = this;
        suixun.ajax(serverUrl+'/simInfoManage/querySimTmpList.json',param,"get",function(data){
            suixun.hideLoding();//隐藏加载中
            if(data.code == 200){
                if( data.info.queryresult != null ){
                    for(var i=0;i<data.info.queryresult.length;i++){
                        var obj=data.info.queryresult[i];
                        importSimData[i] = {id:i,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,createtimestr:obj.createtimestr};
                    }
                }
                otherData.totlepage = data.info.totlepage;
                otherData.totlerows = data.info.totlerows;
                otherData.pageLeft = 0;
                if(data.info.totlepage > 1){
                    otherData.pageRight = 1;
                }else{
                    otherData.pageRight = 0;
                }
                otherData.currentpage = 1;
                currentpage = 1;
                totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                svar.setState({importSimData:importSimData,otherData:otherData});
            }
        });
    },
    //返回
    onClickReturn: function () {
        $(".election-value").html("按条件筛选");
        this.props.onClickSIMDelivery();
//            this.onPageClick(tempCurrentPage);
        importSim.isImportSim = false;
        this.setState({importSim:importSim});
    },
    //撤销操作
    onClickRevoke: function () {
        var svar = this;
        suixun.confirm_noTit("是否撤销数据！",function (data) {
            if(data){
                suixun.showLoding();//显示加载中
                suixun.ajax(serverUrl+'/simInfoManage/cancelSimImport.json','',"get",function(data){
                    suixun.hideLoding(200);//隐藏加载中
                    if(data.code == 200){
                        suixun.alert(data.info.result,function (data) {
                            if(data){
                                svar.onClickReturn();
                                $(".export-imei").val("");
                            }
                        })
                    }else{
                        suixun.alert(data.msg);
                    }
                });
            }
        });
    },
    /**
     * 验证输入框的长度
     * @returns {XML}
     */
    onInputNumber:function (e) {
        var value = e.target.value;
        if(value.length > 11){
            $(e.target).val(value.slice(0,11));
        }
    },
    render: function () {
        {
            var Tabels = simData.map(function (data,index) {
                return (
                    <SIMTable key={data.id} id={data.id} listNumber={index} bindtime={data.bindtime} operations={data.operations}  phone={data.phone}  iccid={data.iccid}  peoplename={data.peoplename}  peopleidcard={data.peopleidcard}  mdtid={data.mdtid} status={data.status} />
                )
            });
            var importTabels = importSimData.map(function (data,index) {
                return (
                    <ImportSIMTable key={data.id} listNumber={index} operations={data.operations}  phone={data.phone}  iccid={data.iccid}  createtimestr={data.createtimestr}  />
                )
            })
        }
        return (
            <div className="outside">
                <div style={{display:importSim.isImportSim == true?"none":"block"}} className="sim-rightTable">
                    <Addbatchnumber onClockSaveAddbatchnumber={this.onClockSaveAddbatchnumber} />
                    <AddSIM onPageClick={this.onPageClick}/>
                    <ImportSimRepeat  />
                    <ExcelInput excelInput={this.excelInput} onClickQueryLastSim={this.onClickQueryLastSim}/>
                    <header >
                        <div className="header-left">
                            <div className="header-left-number" style={{float: "left",color:'#01b4ee',marginLeft:"0px"}}>
                                <span className="header-left-batchid" >{otherData.batchNumber}</span>
                            </div>
                            <div className="header-left-select droup-select" >
                                <div className="election-value">按条件筛选</div>
                                <span className="lower-right-corner" style={{left:"90px"}}/>
                                <div className="drop-down" >
                                    <span className="select-value" data-status="99" onClick={this.onClickSimStatus}>全部</span>
                                    <span className="select-value" data-status="0" onClick={this.onClickSimStatus}>未使用</span>
                                    <span className="select-value" data-status="1" onClick={this.onClickSimStatus}>已使用</span>
                                    <span className="select-value" data-status="-1" onClick={this.onClickSimStatus}>已注销</span>
                                    {/*<span className="select-value" data-status="-2" onClick={this.onClickSimStatus}>已回收</span>*/}
                                </div>
                            </div>
                            <div className="header-left-query">
                                <div className="header-left-query-input">
                                    <input className="queryVal enterEvent" type="text" placeholder="请输入手机号搜索" onInput={this.onInputNumber} style={{top:"-7px"}} name="sim-phone" id="sim-phone"/>
                                    <input type="hidden" name="sim-status" id="sim-status"/>
                                </div>
                                <div className="header-left-query-img" onClick={this.onClickQueryPhone}></div>
                            </div>
                        </div>
                        <div className="header-right ">
                            <div style={{marginRight: '0px',width:'80px'}} className="addButton" onClick={this.onClickQueryLastSim}>最后入库</div>
                            <div style={{marginRight: '0px'}} className="addButton" onClick={this.onClickLogoutSIM}>
                                <span className="addButton-img"><img src="../img/icon/gotOut.png" /></span>
                                <span className="addButton-text">注销</span>
                            </div>
                            <div style={{marginRight: '22px'}} className="addButton" onClick={this.onClickAddSIM}>
                                <span className="addButton-img"><img src="../img/icon/add-white.png" /></span>
                                <span className="addButton-text">新增</span>
                            </div>
                            <div className="export"  style={{marginRight:'15px'}} onClick={this.onClickImportExcel}>
                                <span className="export-img"><img src="../img/icon/import.png" /></span>
                                <span className="export-text">批量导入</span>
                            </div>
                            <div className="export" style={{marginRight:'0px'}}   onClick={this.onClickExportExcel}>
                                <span className="export-img"><img src="../img/icon/export.png" /></span>
                                <span className="export-text" style={{width:"115px",display:'block'}}>导出Excel</span>
                            </div>
                        </div>
                    </header>

                    <div className=" tableInfo">
                        <div className="studentsInfo-data tableInfo-data">
                            <div className="studentsInfo-data-table tableInfo-data-table" >
                                <table className="head-body ">
                                    <thead>
                                        <th style={{width: '3%'}}><input type="checkbox" className="simCheckBox"/></th>
                                        <th style={{width: '4%'}}>序号</th>
                                        <th style={{width: '8%'}}>运营商</th>
                                        <th style={{width: '8%'}}>手机号</th>
                                        <th style={{width: '9%'}}>ICCID</th>
                                        <th style={{width: '8%'}}>激活姓名</th>
                                        <th style={{width: '9%'}}>身份证号</th>
                                        <th style={{width: '8%'}}>关联设备</th>
                                        <th style={{width: '8%'}}>绑定时间</th>
                                        <th style={{width: '8%'}}>状态</th>
                                    </thead>
                                    <tbody className="SIMDelivery-body">
                                        {simData==""?'':Tabels}
                                    </tbody>
                                </table>
                                {simData==""?<div className="tableNoData">{tableNoDataCount}</div>:''}
                            </div>
                        </div>
                        <Page otherData={otherData} onPageClick={this.onPageClick} />
                    </div>
                    <footer id="copyright">
                        <span><img src="../img/icon/copyright.png"/>{copyright}</span>
                    </footer>
                </div>
                <div className="" style={{display:importSim.isImportSim==false?"none":"block"}}>
                    <header >
                        <div className="header-left">
                            <div style={{marginRight: '0px'}} className="addButton" onClick={this.onClickReturn}>
                                <span className="addButton-img"><img style={{position: "relative",top: "6px"}} src="../img/icon/fanhui.png" /></span>
                                <span className="addButton-text">返回</span>
                            </div>
                        </div>
                        <div className="header-right ">
                            <div className="addButton" style={{width:'105px'}} onClick={this.onClickRevoke}>
                                <span className="addButton-img" style={{left: "-34px"}}><img src="../img/icon/gotOut.png" /></span>
                                <span className="addButton-text" style={{width:'75px'}} >全部撤销</span>
                            </div>
                        </div>
                    </header>
                    <div className=" tableInfo">
                        <div className="studentsInfo-data tableInfo-data">
                            <div className="studentsInfo-data-table tableInfo-data-table" >
                                <table className="head-body ">
                                    <thead>
                                        <th style={{width: '10%'}}>序号</th>
                                        <th style={{width: '20%'}}>运营商</th>
                                        <th style={{width: '20%'}}>手机号</th>
                                        <th style={{width: '25%'}}>ICCID</th>
                                        <th style={{width: '25%'}}>导入时间</th>
                                    </thead>
                                    <tbody >
                                        {importSimData==""?'':importTabels}
                                    </tbody>
                                </table>
                                {importSimData==""?<div className="tableNoData">{tableNoDataCount}</div>:''}
                            </div>
                        </div>
                        <Page otherData={otherData} onPageClick={this.onPageClick} />
                    </div>
                    <footer id="copyright">
                        <span><img src="../img/icon/copyright.png"/>{copyright}</span>
                    </footer>
                </div>
            </div>
        )
    },
})

//父组件
var Main = React.createClass({
    //组件初始状态
    getInitialState: function () {
        return {
            otherData:this.props.otherData,
            simData:this.props.simData,
            allSimCount:this.props.allSimCount,
            importSim:this.props.importSim,
            importSimData:this.props.importSimData,
            importSimRepeatData:this.props.importSimRepeatData
        }
    },
    componentDidMount: function () {
        this.onClickSIMDelivery();
        //绑定回车时间
        var svar = this;
        $(document).keypress(function(e) {
            var eCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
            if (eCode == 13){
                if($(".enterEvent").is(":focus")){
                    svar.refs.getOnClickQueryPhone.onClickQueryPhone();
                }
            }
        });
    },
    //SIM卡投放
    onClickSIMDelivery: function () {
        suixun.showLoding();//显示加载中
        otherData.view = "SIMDelivery";
        simData = [];
        var param="param={";
        param = getJsonDataNotEmpty(param,"pagecount",pagecount+"");
        param += "}";
        var svar = this;
        suixun.ajax(serverUrl+'/simInfoManage/querySimInfoList.json',param,"get",function(data){
            setTimeout(function () {
                suixun.hideLoding();//隐藏加载中
            },200);
            if(data.code == 200){
                for(var i=0;i<data.info.queryresult.length;i++){
                    var obj=data.info.queryresult[i];
                    simData[i] = {id:obj.id,bindtime:obj.bindtime,operations:obj.operations,phone:obj.phone,iccid:obj.iccid,status:obj.status,peoplename:obj.peoplename,peopleidcard:obj.peopleidcard,mdtid:obj.mdtid};
                }
                var pageRight = 0;
                if(data.info.totlepage > 1){
                    pageRight = 1;
                }
                otherData = {maxHeight:height,currentpage:1,totlepage:data.info.totlepage,totlerows:data.info.totlerows,pageLeft:0,pageRight:pageRight,view:'SIMDelivery'};
                currentpage = 1;totlepage = data.info.totlepage;//初始化的时候赋值：分页的当前页和总的页数
                allSimCount=data.info.totlerows;
                svar.setState({simData:simData,otherData:otherData,allSimCount:allSimCount});
                $(".simChildCheckBox").attr("checked",false);
                $(".simCheckBox").attr("checked",false);
            }
        });
    },
    //下载Excel模版
    excleModel: function () {
        suixun.confirm_noTit("是否导出Excel模版？",function (data) {
            if(data){
                window.location.href = serverUrl+"/simInfoManage/export_simTamplate.json";
            }
        });
    },
    render: function () {
        return (
            <div className="outside" >
                <div className="header-menu">
                    <ul>
                        <li><a href="../schoolManage/querySchoolList.html">学校</a></li>
                        <li><a href="../deviceInitManage/queryDeviceInitList.html">设备管理</a></li>
                        <li onClick={this.onClickSIMDelivery} className="select" >SIM卡管理</li>
                        <li style={{display:"none"}}><a href="../packageManage/queryPackageList.html">设备套餐</a></li>
                        <li style={{display:"none"}}><a href="../devicePriceManage/queryDevicePriceList.html">设备零售价</a></li>
                        <li><a href="../deviceonReserve/queryonReserveList.html">区域储备量</a></li>
                        <li><a href="../attendance/attendanceMange.html">考勤机管理</a></li>
                    </ul>
                    <div onClick={this.excleModel} className="excleModel" >
                        <img src="../img/icon/annotations.png" />
                        <span>导出Excel模版下载</span>
                    </div>
                </div>
                <div className="SIMDelivery tableManage-body">
                    <SIMDelivery onClickSIMDelivery={this.onClickSIMDelivery} ref="getOnClickQueryPhone"/>
                </div>
            </div>
        );
    }
});
ReactDOM.render(
    <Main  otherData={otherData} simData={simData}  allSimCount={allSimCount} importSim={importSim} importSimData={importSimData} importSimRepeatData={importSimRepeatData} />,
    document.getElementById('tableManage')
);

//点击下拉框
$(".header-left-select").click(function () {
    var dropDown = $(this).find('.drop-down');
    if(dropDown.is(":hidden")){
        dropDown.slideDown();
    }else{
        dropDown.slideUp();
    }
});
//设置main页面右边的最小宽度
/*$('.main-right', window.parent.document).css("minWidth","1274px");*/
$(".parentCheckBox").click(function(){
    if($(".parentCheckBox").is(":checked")){
        $(".childrenCheckBox").prop("checked",true);
    }else{
        $(".childrenCheckBox").attr("checked",false);
    }
});
//sim卡管理
$(".simCheckBox").click(function(){
    if($(".simCheckBox").is(":checked")){
        $(".simChildCheckBox").prop("checked",true);
    }else{
        $(".simChildCheckBox").attr("checked",false);
    }
});
